<?php

/**
52zll.top
 */

if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
	exit('Access Denied');
}

$lang = array_merge($lang, $scriptlang['dzapp_zhibo']);
require_once libfile('function/base', 'plugin/dzapp_base');

if(empty($_GET['ac'])) {

	if(!submitcheck('listsubmit')) {

		showformheader('plugins&operation=config&identifier=dzapp_zhibo&pmod=admincp_live');
		showtableheader();
		showsubtitle(array('del', 'machine', 'push_url', 'play_query', ''));
		$perpage = 20;
		$start = ($page - 1) * $perpage;
		$mpurl = ADMINSCRIPT."?action=plugins&operation=config&identifier=dzapp_zhibo&pmod=admincp_live";
		$param = array(
			array('activity_id', $_GET['activity_id'])
		);
		$count = C::t('#dzapp_zhibo#dzapp_zhibo_live')->count_by_search($param);
		if($count) {
			$query = C::t('#dzapp_zhibo#dzapp_zhibo_live')->fetch_all_by_search($param, $start, $perpage);
			foreach($query as $value) {
				showtablerow('', array('class="td25"'), array(
					'<input type="checkbox" class="checkbox" name="delete[]" value="'.$value['live_id'].'" />',
					$value['machine'],
					$value['push_url'],
					$value['play_query'],
					'<a href="'.ADMINSCRIPT.'?action=plugins&operation=config&identifier=dzapp_zhibo&pmod=admincp_live&ac=edit&id='.$value['live_id'].'">'.cplang('edit').'</a>'
				));
			}
			$multipage = multi($count, $perpage, $page, $mpurl);
		}
		echo '<tr><td></td><td colspan="20"><div><a href="'.ADMINSCRIPT.'?action=plugins&operation=config&identifier=dzapp_zhibo&pmod=admincp_live&ac=add" class="addtr">'.cplang('add_live').'</a></div></td></tr>';
		showsubmit('listsubmit', 'submit', 'del', '', $multipage);
		showtablefooter();
		showformfooter();

	} else {

		if(is_array($_GET['delete'])) {
			C::t('#dzapp_zhibo#dzapp_zhibo_live')->delete($_GET['delete']);
		}

		cpmsg('live_update_succeed', 'action=plugins&operation=config&identifier=dzapp_zhibo&pmod=admincp_live', 'succeed');
	}

} elseif($_GET['ac'] == 'add') {
	
	if(!submitcheck('addsubmit')) {

		showformheader('plugins&operation=config&identifier=dzapp_zhibo&pmod=admincp_live&ac=add');
		showtableheader();
		
		showsubmit('addsubmit', 'submit'); 
		showtablefooter();
		showformfooter();

	} else {

		if(!$_GET['machine']) {
			cpmsg('live_invalid', '', 'error');
		}
		
		$data = array(
			'dateline' => $_G['timestamp'],'ip' => $_G['clientip'],
		);
		C::t('#dzapp_zhibo#dzapp_zhibo_live')->insert($data);

		cpmsg('live_add_succeed', 'action=plugins&operation=config&identifier=dzapp_zhibo&pmod=admincp_live', 'succeed');
	}

} elseif($_GET['ac'] == 'edit') {

	$live = C::t('#dzapp_zhibo#dzapp_zhibo_live')->fetch($_GET['id']);
	if(empty($live)) {
		cpmsg('live_nonexistence', '', 'error');
	}
	
	if(!submitcheck('editsubmit')) {

		showformheader('plugins&operation=config&identifier=dzapp_zhibo&pmod=admincp_live&ac=edit&id='.$live['live_id']);
		showtableheader();
		
		showsubmit('editsubmit', 'submit'); 
		showtablefooter();
		showformfooter();

	} else {

		if(!$_GET['machine']) {
			cpmsg('live_invalid', '', 'error');
		}
		
		$data = array(
			
		);
		C::t('#dzapp_zhibo#dzapp_zhibo_live')->update($live['live_id'], $data);

		cpmsg('live_edit_succeed', 'action=plugins&operation=config&identifier=dzapp_zhibo&pmod=admincp_live', 'succeed');
	}
}
//From:www_caogen8_co
?>